package com.demo.xrom.ssh.dao;

import java.util.Map;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.demo.xrom.ssh.entity.Person;
import com.smart.common.dao.AbstractDao;
import com.smart.common.util.Page;
import com.smart.common.util.PageRequest;
import com.smart.tools.ObjectHelper;

/**
 * 
 * 版权所有：xxxxxxx
 * @Description: TODO
 * @Title: PersonDao.java 
 * @ClassName: PersonDao 
 * @author tangyan 
 * @date 2019年2月12日 上午11:07:51 
 * @version V1.0
 */
@Repository
@Transactional
public class PersonDao  extends AbstractDao<Person>{
	
	
	/**
	 * 
	 * @Title: queryPersonPage 
	 * @Description: 分页查询
	 * @author tangyan 
	 * @param pageRequest
	 * @param conditions
	 * @return
	 */
	public Page<Person> queryPersonPage(PageRequest pageRequest, Map<String, Object> conditions){
		
		StringBuffer hql = new StringBuffer(" from  Person  p  where  p.isDeleted = 0 ");
		
		if(ObjectHelper.isNotEmpty(conditions.get("username"))){
			hql.append("  and  p.username like :username");
			conditions.put("username", "%"+conditions.get("username")+"%");
		}
		
		if(ObjectHelper.isNotEmpty(conditions.get("phone"))){
			hql.append("  and  p.phone = :phone");
		}
		
		return  this.findByHql(pageRequest, hql.toString(), conditions);
				
	}
}
